package servlet.Jamin;

import net.sf.json.JSONObject;
import pojo.Coupon;
import service.impl.CouponServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;

@WebServlet(value = "/ModifyServelt")
public class ModifyCoupon extends HttpServlet {
CouponServiceImpl cs=new CouponServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("c_id");
        String description = req.getParameter("c_description");
        String term = req.getParameter("c_term");
        String vipprice=req.getParameter("c_vipprice");
        String deadline=req.getParameter("c_deadline");
        Coupon coupon=new Coupon();
        coupon.setcID(Integer.parseInt(id));
        coupon.setcDescription(description);
        coupon.setcTerm(Integer.parseInt(term));
        coupon.setcVipPrice(Integer.parseInt(vipprice));
        coupon.setcDeadline(Timestamp.valueOf(deadline));
        int a=cs.updateCoupon(coupon);
        JSONObject js=new JSONObject();
        if (a!=0){
            js.put("update",true);
        }else{
            js.put("update",false);
        }
        PrintWriter out = resp.getWriter();
        out.print(js);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
